package com.tianqu.tms.www.cardect.action;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.www.cardect.actionform.CarNormalDetectForm;
import com.tianqu.tms.www.cardect.viewhelper.CarNormalDetectViewHelper;
/**
 * 车辆基本检测信息录入首页提交分发页
 * 
 * @author tianshifu
 *
 */
public class CarWDPersonNormalDetectTopDispatchAction extends TmsAction {
	private Logger logger = Logger.getLogger(CarWDPersonNormalDetectTopDispatchAction.class);//log
	private static final String DETECT_POSITION = "detect_position";//检测位置，标识哪个button提交
	private static final String DETECT_INPUT_DATA = "detect_input_data";//检测录入信息
	private static final String SAVE_STATUS = "save_status";//保存状态
	private static final String IMGKEY = "imgKey";// 图片位置
	private static final String IMGTYPE = "imgType";// 图片类型
	private static final String CHKMODEL = "chkModel";//检测模式

	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");	
		//在form中定义button，每次提交都记录页面信息,跳转到不同的页面
		CarNormalDetectForm normalDetectForm = (CarNormalDetectForm)form;
		
		String actionForward = "";//定义跳转路径
	
		//normalToSeniorDetectButton
		if(normalDetectForm.getNormalToSeniorDetectButton()!=null)
		{
			//往viewhelp中放一个值
			actionForward = "normalToSeniorDetectConfirm";//普通检测切换到高级检测确认页
		}
		/***图片 都走一个Action*************************************************/
		if(normalDetectForm.getZqImageButton()!=null)
		{
			uc.setAttribute(IMGTYPE, "1");
			uc.setAttribute(IMGKEY, "1");
			uc.setAttribute(CHKMODEL, "1");			
			actionForward = "normalDetectImageForward";//首页八张图跳转到图片上传页
		}
		if(normalDetectForm.getYqImageButton()!=null)
		{
			uc.setAttribute(IMGTYPE, "1");
			uc.setAttribute(IMGKEY, "2");
			uc.setAttribute(CHKMODEL, "1");
			actionForward = "normalDetectImageForward";//
		}
		if(normalDetectForm.getZhImageButton()!=null)
		{
			uc.setAttribute(IMGTYPE, "1");
			uc.setAttribute(IMGKEY, "3");
			uc.setAttribute(CHKMODEL, "1");
			actionForward = "normalDetectImageForward";//
		}
		if(normalDetectForm.getYhImageButton()!=null)
		{
			uc.setAttribute(IMGTYPE, "1");
			uc.setAttribute(IMGKEY, "4");
			uc.setAttribute(CHKMODEL, "1");
			actionForward = "normalDetectImageForward";//
		}
		if(normalDetectForm.getQpzjImageButton()!=null)
		{
			uc.setAttribute(IMGTYPE, "1");
			uc.setAttribute(IMGKEY, "7");
			uc.setAttribute(CHKMODEL, "1");
			actionForward = "normalDetectImageForward";//
		}
		if(normalDetectForm.getHpzjImageButton()!=null)
		{
			uc.setAttribute(IMGTYPE, "1");
			uc.setAttribute(IMGKEY, "8");
			uc.setAttribute(CHKMODEL, "1");
			actionForward = "normalDetectImageForward";//
		}
		if(normalDetectForm.getZktImageButton()!=null)
		{
			uc.setAttribute(IMGTYPE, "1");
			uc.setAttribute(IMGKEY, "6");
			uc.setAttribute(CHKMODEL, "1");
			actionForward = "normalDetectImageForward";//
		}
		if(normalDetectForm.getYbpImageButton()!=null)
		{
			uc.setAttribute(IMGTYPE, "1");
			uc.setAttribute(IMGKEY, "5");
			uc.setAttribute(CHKMODEL, "1");
			actionForward = "normalDetectImageForward";//首页八张图跳转到图片上传页
		}
		if(normalDetectForm.getJcImageButton()!=null)
		{
			uc.setAttribute(IMGTYPE, "1");
			uc.setAttribute(IMGKEY, "9");
			uc.setAttribute(CHKMODEL, "1");
			actionForward = "normalDetectImageForward";//新加检测图片
		}
		/***图片*************************************************/
		/***********检测跳转 都跳到一个Action中进行处理 传一个检测按钮位置标识来判断存入哪快的数据  ************************************/
		//frontLeftChkButton //一、左前门检测录入
		if(normalDetectForm.getFrontLeftChkButton()!=null)
		{
			
			uc.removeAttribute(DETECT_POSITION);
			uc.setAttribute(DETECT_POSITION, "1");
			actionForward = "normalDetectDataInput";//跳转到检测信息录入页面
		}
		//insideChkButton //二、内饰检测录入
		if(normalDetectForm.getInsideChkButton()!=null)
		{
			uc.removeAttribute(DETECT_POSITION);
			uc.setAttribute(DETECT_POSITION, "2");
			actionForward = "normalDetectDataInput";			
		}
		//panelFenerLhChkButton //三、左前翼子板检测录入
		if(normalDetectForm.getPanelFenerLhChkButton()!=null)
		{
			uc.removeAttribute(DETECT_POSITION);
			uc.setAttribute(DETECT_POSITION, "3");
			actionForward = "normalDetectDataInput";			
		}
		//deadAheadChkButton  //四、正前面检测录入
		if(normalDetectForm.getDeadAheadChkButton()!=null)
		{
			uc.removeAttribute(DETECT_POSITION);
			uc.setAttribute(DETECT_POSITION, "4");
			actionForward = "normalDetectDataInput";			
		}
		//engineChkButton   //五、发动机舱内检测录入
		if(normalDetectForm.getEngineChkButton()!=null)
		{
			uc.removeAttribute(DETECT_POSITION);
			uc.setAttribute(DETECT_POSITION, "5");
			actionForward = "normalDetectDataInput";			
		}
		//panelFenerRhChkButton   //六、右前翼子板检测录入
		if(normalDetectForm.getPanelFenerRhChkButton()!=null)
		{
			uc.removeAttribute(DETECT_POSITION);
			uc.setAttribute(DETECT_POSITION, "6");
			actionForward = "normalDetectDataInput";			
		}
		//frontRightChkButton   //七、右前门检测录入
		if(normalDetectForm.getFrontRightChkButton()!=null)
		{
			uc.removeAttribute(DETECT_POSITION);
			uc.setAttribute(DETECT_POSITION, "7");
			actionForward = "normalDetectDataInput";			
		}
		//rearRightChkButton   //八、右后门检测录入
		if(normalDetectForm.getRearRightChkButton()!=null)
		{
			uc.removeAttribute(DETECT_POSITION);
			uc.setAttribute(DETECT_POSITION, "8");
			actionForward = "normalDetectDataInput";			
		}
		//fenderRaChkButton   //九、右后翼子板检测录入
		if(normalDetectForm.getFenderRaChkButton()!=null)
		{
			uc.removeAttribute(DETECT_POSITION);
			uc.setAttribute(DETECT_POSITION, "9");
			actionForward = "normalDetectDataInput";			
		}
		//rightAsternChkButton  //十、正后面检测录入
		if(normalDetectForm.getRightAsternChkButton()!=null)
		{
			uc.removeAttribute(DETECT_POSITION);
			uc.setAttribute(DETECT_POSITION, "10");
			actionForward = "normalDetectDataInput";			
		}
		//luggageChkButton   //十一、行李箱内侧检测录入
		if(normalDetectForm.getLuggageChkButton()!=null)
		{
			uc.removeAttribute(DETECT_POSITION);
			uc.setAttribute(DETECT_POSITION, "11");
			actionForward = "normalDetectDataInput";			
		}
		//fenderLaChkButton  //十二、左后翼子板检测录入
		if(normalDetectForm.getFenderLaChkButton()!=null)
		{
			uc.removeAttribute(DETECT_POSITION);
			uc.setAttribute(DETECT_POSITION, "12");
			actionForward = "normalDetectDataInput";			
		}
		//rearLeftChkButton  //十三、左后门检测录入
		if(normalDetectForm.getRearLeftChkButton()!=null)
		{
			uc.removeAttribute(DETECT_POSITION);
			uc.setAttribute(DETECT_POSITION, "13");
			actionForward = "normalDetectDataInput";			
		}
		//carRoofChkButton   //十四、车顶检测录入
		if(normalDetectForm.getCarRoofChkButton()!=null)
		{
			uc.removeAttribute(DETECT_POSITION);
			uc.setAttribute(DETECT_POSITION, "14");
			actionForward = "normalDetectDataInput";			
		}
		//carDescribeInputButton  //检测说明录入
		if(normalDetectForm.getCarDescribeInputButton()!=null)
		{
			
			uc.removeAttribute(DETECT_POSITION);
			uc.setAttribute(DETECT_POSITION, "15");
			actionForward = "normalDetectDataInput";
		}
		//toDetectAllOverbutton  //保存 状态变成6
		if(normalDetectForm.getToDetectAllOverbutton()!=null)
		{
			actionForward = "normalDetectDataSubmitConfirm";//跳转到提交确认页	
			uc.setAttribute(SAVE_STATUS, "6");//确认完了
		}	
		//toDetecNowOverbutton   //暂时保存
		if(normalDetectForm.getToDetecNowOverbutton()!=null)
		{
			actionForward = "normalDetectDataSubmitConfirm";//跳转到暂时保存确认页	
			uc.setAttribute(SAVE_STATUS, "3");//待检测人工
		}		
		
		
		//需要将页面的信息取出来放到uc中供返回的时候调用 （只set配置信息 表显里程整车检测）
		CarNormalDetectViewHelper view = new CarNormalDetectViewHelper();
		if(uc.getAttribute(DETECT_INPUT_DATA)!=null)
		{
			view = (CarNormalDetectViewHelper)uc.getAttribute(DETECT_INPUT_DATA);
		}
		view = setViewhelpFromForm(view,normalDetectForm);
		
		uc.setAttribute(DETECT_INPUT_DATA, view);
		logger.debug(this.getClass().getName() + "#doAction was completed.");
		return mapping.findForward(actionForward);
	}
	/**
	 * 将页面form值set到viewhelp中
	 */
	private CarNormalDetectViewHelper setViewhelpFromForm(CarNormalDetectViewHelper view,CarNormalDetectForm form)
	{
		/********** 整车八大配置  + 表显里程 ****/
		view.setSkylight(form.getSkylight());
		view.setLeatherSeats(form.getLeatherSeats());
		view.setAluminumRim(form.getAluminumRim());
		view.setGpsNavigation(form.getGpsNavigation());
		view.setAbs(form.getAbs());
		view.setAutoWindow(form.getAutoWindow());
		view.setSrsNumber(form.getSrsNumber());
		view.setFourWheelDrive(form.getFourWheelDrive());
		view.setMileage(form.getMileage());
		view.setDisasterCars(form.getDisasterCars());
		
		return view;
	}
}
